package com.bird.component.database.model

import com.baomidou.mybatisplus.annotation.FieldFill
import com.baomidou.mybatisplus.annotation.IdType
import com.baomidou.mybatisplus.annotation.TableField
import com.baomidou.mybatisplus.annotation.TableId
import com.baomidou.mybatisplus.annotation.TableLogic
import com.bird.component.ddd.model.entity.BaseEntity
import com.fasterxml.jackson.annotation.JsonFormat
import org.springframework.format.annotation.DateTimeFormat
import java.time.LocalDateTime

open class BaseDO {
    @TableId(type = IdType.ASSIGN_ID)
    var id: Long? = null

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    var createTime: LocalDateTime? = null
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT_UPDATE)
    var updateTime: LocalDateTime? = null
    @TableField(fill = FieldFill.INSERT)
    var createBy: Long? = null
    @TableField(fill = FieldFill.INSERT_UPDATE)
    var updateBy: Long? = null
    @TableLogic
    var isDeleted: Int = 0

    fun richBase(baseEntity: BaseEntity): BaseDO {
        this.id = baseEntity.id
        this.createTime = baseEntity.createTime
        this.updateTime = baseEntity.updateTime
        this.createBy = baseEntity.createBy
        this.updateBy = baseEntity.updateBy
        return this
    }
}
fun BaseEntity.richEntity(baseDO: BaseDO) {
    this.id = baseDO.id
    this.createTime = baseDO.createTime
    this.updateTime = baseDO.updateTime
    this.createBy = baseDO.createBy
    this.updateBy = baseDO.updateBy
}


